package com.icss.flow.config;


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
/**
 * Boolean转换Integer序列化器
 * @author WZG
 * @date 2024年04月09日 16:34
 */

public class BooleanToIntJsonDeserializer extends JsonDeserializer<Integer> {

    @Override
    public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        JsonToken currentToken = p.getCurrentToken();
        if (currentToken == JsonToken.VALUE_TRUE) {
            return 1;
        } else if (currentToken == JsonToken.VALUE_FALSE) {
            return 0;
        } else {
            throw ctxt.mappingException("Expected a Boolean value, but got: " + currentToken);
        }
    }
}
